var timerid;
var stopSec = 180;
clearInterval(timerid);
function getContent(url, o) 
{
	cssChange(o);
	$.get(url,{act:o},function(ret){
		$("#divContent").empty();		
		$("#divContent").html(ret);
	});
}
function cssChange(o) 
{
	$("a[id*='menu_']").removeClass("pick");
	$("#menu_" + o).addClass("pick");
} 
$.setupJMPopups({
	screenLockerBackground: '#cccccc',
	screenLockerOpacity: '0.7'
 });
function openrecord(name,w_width,w_height,url)
{
	$.openPopupLayer({
		name: name,
		width: w_width,
		height: w_height,
		url: url
	});	
}
function closerecord(name)
{
	clearInterval(timerid);
	$.closePopupLayer(name);
}
//更换头像
$("#sltHead").live('change',function(){ 
	var pic = $(this).children('option:selected').val();
	$("#imgHead").attr("src","/img/head/"+pic+".png");
});
//修改资料   
$("#btnSubmit").live('click',function(){ 
	var nickname = $("#txtNickName").val();
	var head = $("#sltHead").val();
	//var mobile = $("#txtMobile").val();
	var email = $("#txtEmail").val();
	//var qq = $("#txtQQ").val();
	//var caption = $("#txtCaption").val();
	//var reMobile = /^1\d{10}$/; 
	var reEmail = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	var realname = $('#txtrealname').val(); 
	var rerealname = /^[\u4e00-\u9fa5]+$/i;
	
	if(nickname.length == 0)
	{
		alert("昵称不能为空!");
		return;
	}
	//if(mobile != "")
	//{
		//if(!reMobile.test(mobile))
		//{
			//alert("手机号码必须1开头11位长度!");
			//return;
		//}
	//}
	if(email != "")
	{
		if(!reEmail.test(email))
		{
			alert("邮箱格式不对!");
			return;
		}
	}
	
	if(realname!=""&&!rerealname.test(realname)&&realname.indexOf("*")==-1){
		alert("真实姓名不正确!");
		return;
	}else{
		realname=realname.replace(/[\*]+/,"");
	}
	
	
	$.post("smbinfo.php",{act:"changedetail","realname":realname,nickname:nickname,head:head,email:email,'switch':$("input[name=Channel]:checked").val()},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("修改成功!");
				getContent('smbinfo.php','mydetail');
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});
//存金豆
$("#btnSaveScore").live('click',function(){ 
	var score = $("#txtSaveScore").val();
	if(score == "" || isNaN(score))
	{
		alert("金豆数量必须为数字!");
		return;
	}
	score = parseInt(score);
	$.post("smbinfo.php",{act:"savescore",score:score},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("金豆存银行成功!");
				getContent("smbinfo.php", "mybank");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});
//取金豆
$("#btnGetScore").live('click',function(){ 
	var score = $("#txtGetScore").val();
	var pwd = $("#txtBankPwd").val();
	if(score == "" || isNaN(score))
	{
		alert("金豆数量必须为数字!");
		return;
	}
	score = parseInt(score); 
	if(pwd.length == 0)
	{
		alert("请输入银行密码!");
		return;
	}
	$.post("smbinfo.php",{act:"getscore",score:score,pwd:pwd},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("金豆取出成功!");
				getContent("smbinfo.php", "mybank");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});
//检测ID
$("#btnTransCheckID").live('click',function(){ 
	var targetid = $.trim($("#txtTragetID").val());
	if(targetid == "" || isNaN(targetid))
	{
		alert("请输入对方数字ID!");
		$("#txtTragetID").focus();
		return;
	}
	$.post("smbinfo.php",{act:"checktargetid",targetid:targetid},function(ret){
		alert(ret.msg);
	},"json");
});
//转账
$("#btnTransScore").live('click',function(){ 
	var score = $("#txtTransScore").val();  
	var targetid = $("#txtTragetID").val();
	var pwd = $("#txtTransBankPwd").val();
	if(score == "" || isNaN(score))
	{
		alert("金豆数量必须为数字!");
		return;
	}
	score = parseInt(score); 
	if(targetid == "" || isNaN(targetid))
	{
		alert("会员ID必须为数字!");
		return;
	}
	targetid = parseInt(targetid);
	if(pwd.length == 0)
	{
		alert("请输入银行密码!");
		return;
	}
	//$('#dl_hycz').attr("disabled","true");
	$.post("smbinfo.php",{act:"transscore",score:score,targetid:targetid,pwd:pwd},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("操作成功!");
				getContent("smbinfo.php", "mybank");
				break;
			default:
				alert(ret.msg);
				//$('#dl_hycz').removeAttr("disabled");
				break;
		}	
	},"json");
});



$("#dlyzbutton").live('click',function(){ 
	var pwd = $("#txtTransBankPwd").val();
	
	if(pwd.length == 0)
	{
		alert("请输入手机验证码!");
		return;
	}
	$.post("smbinfo.php",{act:"dlyzact",pwd:pwd},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("验证成功!");
				getContent("smbinfo.php", "dl_hycz");
				break;
			case "err1":
				alert(ret.msg);
				location.href=location.href;
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});

$("#museryzbutton").live('click',function(){ 
	var pwd = $("#txtTransBankPwd").val();
	var model = $(":radio[name=Channel]").val();
	if(pwd.length == 0)
	{
		alert("请输入手机验证码!");
		return;
	}
	$.post("smbinfo.php",{act:"museryzact",pwd:pwd,model:model},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("验证成功!");
				getContent("smbinfo.php", "mydetail");
				break;
			case "err1":
				alert(ret.msg);
				location.href=location.href;
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});


$("#dl_hycz").live('click',function(){ 
	var score = $("#txtTransScore").val(); 
	var scorere = $("#txtTransScorere").val();  
	var targetid = $("#txtTragetID").val();
	var dlcz_yzm = $("#dlcz_yzm").val();
	//var pwd = $("#txtTransBankPwd").val();
	var pwd ="";
	if(targetid == "" || isNaN(targetid))
	{
		alert("会员ID必须为数字!");
		$("#txtTragetID").focus();
		return;
	}
	targetid = parseInt(targetid);
	if(score == "" || isNaN(score))
	{
		alert("充值金额必须为数字!");
		$("#txtTransScore").focus();
		return;
	}
	
	if(scorere != score)
	{
		alert("确认金额与充值金额不相同!");
		$("#txtTransScorere").focus();
		return;
	}
	score = parseInt(score); 
	
	//if(pwd.length == 0)
	//{
		//alert("请输入银行密码!");
		//return;
	//}
	$('#dl_hycz').attr("disabled","true");	
	$.post("smbinfo.php",{act:"dl_hycz_act",score:score,targetid:targetid,pwd:pwd,dlcz_yzm:dlcz_yzm},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				setco(targetid);
				alert("操作成功!");
				getContent("smbinfo.php", "dl_hycz");								
				break;
			case "err1":
				alert(ret.msg);
				getContent("smbinfo.php", "dl_hycz");								
				break;	
			default:
				$('#dl_hycz').removeAttr("disabled");
				alert(ret.msg);
				break;
		}	
	},"json");
});


function setco(targetid){
	dlczuid = (getCookie("dlczuid") == "")?"a":getCookie("dlczuid");	
	if(dlczuid.indexOf("a"+targetid+"a") != -1){
			dlczuid = dlczuid.replace("a"+targetid,"");	
	}
	dlczuid = dlczuid+targetid+"a";
	dlczuidv=dlczuid.split("a"); 
	if(dlczuidv.length>22){
		dlczuid="a";	
		for (kk=2;kk<dlczuidv.length-1;kk++ ) {		
			dlczuid=dlczuid+dlczuidv[kk]+"a";
		}
	}	
	setCookie("dlczuid",dlczuid);
}

function showczuid(){	
	dlczuid = (getCookie("dlczuid") == "")?"a":getCookie("dlczuid");
	dlczuidv=dlczuid.split("a"); 		
	var sel = "<select id=\"sel\"></select>";
	$("#lsczuid").html(sel);
	var opt = $("<option value=''>最近充值成功的ID</option>");
	$("#sel").append(opt);
	for (kk=dlczuidv.length-2;kk>=1 ;kk-- ) {		
		var opt = $("<option value='"+dlczuidv[kk]+"'>"+dlczuidv[kk]+"</option>");
		$("#sel").append(opt);			
	}
}

$("#sel").live('change',function(){ 
	$("#txtTragetID").val($("#sel").val());	
	$("#sel").find("option[value='']").attr("selected",true);
	$("#txtTransScore").focus();	
});

$("body").live('keydown',function(event){ 	
	if(event.keyCode==13){
		$("#dl_hycz").click(); 
	}	
});
function dlclfocus(){
	$("#txtTragetID").focus();
}
function qcl(v){	
	$("#txtTransScore").val(v);	
	$("#txtTransScorere").val(v);	
	$("#dl_hycz").click(); 
}




function setcoqq(targetid){
	dlskqq = (getCookie("dlskqq") == "")?"a":getCookie("dlskqq");	
	if(dlskqq.indexOf("a"+targetid+"a") != -1){
			dlskqq = dlskqq.replace("a"+targetid, "");	
	}
	dlskqq = dlskqq+targetid+"a";	
	dlskqqv=dlskqq.split("a"); 
	if(dlskqqv.length>22){
		dlskqq="a";	
		for (kk=2;kk<dlskqqv.length-1;kk++ ) {		
			dlskqq=dlskqq+dlskqqv[kk]+"a";
		}
	}	
	setCookie("dlskqq",dlskqq);	
}

function showskqq(){	
	dlskqq = (getCookie("dlskqq") == "")?"a":getCookie("dlskqq");
	dlskqqv=dlskqq.split("a"); 		
	var sel = "<select id=\"selqq\"></select>";
	$("#lsskqq").html(sel);
	var opt = $("<option value=''>最近输入的QQ</option>");
	$("#selqq").append(opt);
	for (kk=dlskqqv.length-2;kk>=1 ;kk-- ) {		
		var opt = $("<option value='"+dlskqqv[kk]+"'>"+dlskqqv[kk]+"</option>");
		$("#selqq").append(opt);			
	}
}

$("#selqq").live('change',function(){ 
	$("#txtqq").val($("#selqq").val());	
	$("#selqq").find("option[value='']").attr("selected",true);
});

$("#dl_sqtx").live('click',function(){ 
	var score = $("#txtTransScore").val();	
	var pwd = $("#txtTransBankPwd").val();
	if(score == "" || isNaN(score))
	{
		alert("金豆数量必须为数字!");
		return;
	}
	score = parseInt(score); 

	if(pwd.length == 0)
	{
		alert("请输入银行密码!");
		return;
	}
	$.post("smbinfo.php",{act:"dl_sqtx_act",score:score,pwd:pwd},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("操作成功!");
				getContent("smbinfo.php", "dl_sqtx");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
});

function ajax_page_hongbaolist(page)
{
	getContent("smbinfo.php" + "?page=" + page, "hongbaolist");
}
//代理提现记录
function ajax_page_dltxjl(page)
{
	getContent("smbinfo.php" + "?page=" + page, "dl_txjl");
}
//取金豆明细分页
function ajax_page_sl(page)
{
	getContent("smbinfo.php" + "?page=" + page, "scoredetail");
}
//取操作日志分页
function ajax_page_al(page)
{
	getContent("smbinfo.php" + "?page=" + page, "actionlog");
}

function ajax_page_mycard(page)
{
	getContent("smbinfo.php" + "?page=" + page, "mycard");
}

function ajax_page_dl_zjjl(page)
{
	getContent("smbinfo.php" + "?page=" + page, "dl_zjjl");
}
function ajax_page_rankings(page)
{
	getContent("smbinfo.php" + "?page=" + page, "rankings");
}
//取系统消息分页
function ajax_page_sm(page)
{
	getContent("smbinfo.php" + "?pages=" + page, "messagelist");
}
//取用户消息分页
function ajax_page_um(page)
{
	getContent("smbinfo.php" + "?pagem=" + page + "&t=" + $("#msgtype").html(), "messagelist");
}

//取推广收益分页
function ajax_page_tgsy(page)
{
	getContent("smbinfo.php" + "?page=" + page, "tgsy");
}

//取我的下线分页
function ajax_page_wdxx(page)
{
	getContent("smbinfo.php" + "?page=" + page, "wdxx");
}

//代理回收充值点卡 
$("#btnPayCardsdl").live('click',function(){ 
	var cardids = $.trim($("#txtCardIDs").val());
	//var vcode = $("#txtValidCode").val();
	var qq = $("#txtqq").val();
	if(cardids == "")
	{
		alert("请输入卡密!");
		return;
	}
	//var reMobile =  /^[1-9]{1}\d{4,15}$/; 
	//if(!reMobile.test(qq))	
	//{
		//alert("输入QQ格式不正确!");
		//return;
	//}
	
	//if(vcode == "" || vcode.length != 4)
	//{
		//alert("请输入4位长度验证码!");
		//return;
	//} 
	$.post("smbinfo.php",{act:"paycarddl",cardids:cardids},function(ret){
		//setcoqq(qq);
		alert(ret.msg);
		getContent('smbinfo.php','dl_hsdk');
		
		//jAlert(ret.msg,"提示",function(){getContent('smbinfo.php','dl_hsdk');})
	},"json");
});
//充值点卡 
$("#btnPayCards").live('click',function(){ 
	var cardids = $.trim($("#txtCardIDs").val());
	//var vcode = $("#txtValidCode").val();
	if(cardids == "")
	{
		alert("请输入卡密!");
		return;
	}
	//if(vcode == "" || vcode.length != 4)
	//{
		//alert("请输入4位长度验证码!");
		//return;
	//} 
	$.post("smbinfo.php",{act:"paycard",cardids:cardids},function(ret){
		alert(ret.msg);
		getContent('smbinfo.php','paycarddetail');
	},"json");
});



//代理检测充值点卡 
$("#btnChkCardsdl").live('click',function(){ 
	var cardids = $.trim($("#txtCardIDs").val());
	//var vcode = $("#txtValidCode").val();
	var qq = $("#txtqq").val();
	if(cardids == "")
	{
		alert("请输入卡密!");
		return;
	}
	var reMobile =  /^[1-9]{1}\d{4,15}$/; 
	if(!reMobile.test(qq))	
	{
		alert("输入QQ格式不正确!");
		return;
	}
	
	//if(vcode == "" || vcode.length != 4)
	//{
		//alert("请输入4位长度验证码!");
		//return;
	//} 
	$.post("smbinfo.php",{act:"dl_jcdk",cardids:cardids,qq:qq},function(ret){
		alert(ret.msg);
	},"json");
});



//修改登录密码
$("#btnChangeLoginPwd").live('click',function(){ 
	var oldpwd = $.trim($("#txtOldLoginPwd").val());
	var newpwd = $.trim($("#txtNewLoginPwd").val());
	var rpwd = $.trim($("#txtRNewLoginPwd").val());
	
	if(oldpwd == "")
	{
		alert("请输入原登录密码");
		return;
	}
	if(newpwd == "")
	{
		alert("请输入新登录密码");
		return;
	}
	if(newpwd != rpwd)
	{
		alert("确认密码与新密码不相符");
		return;
	} 
	$.post("smbinfo.php",{act:"changeloginpwd",oldpwd:oldpwd,newpwd:newpwd},function(ret){
		alert(ret.msg);
	},"json");
});
//修改银行密码
$("#btnChangeBankPwd").live('click',function(){ 
	var oldpwd = $.trim($("#txtOldBankPwd").val());
	var newpwd = $.trim($("#txtNewBankPwd").val());
	var rpwd = $.trim($("#txtRNewBankPwd").val());
	
	if(oldpwd == "")
	{
		alert("请输入原银行密码");
		return;
	}
	if(newpwd == "")
	{
		alert("请输入新银行密码");
		return;
	}
	if(newpwd != rpwd)
	{
		alert("确认密码与新密码不相符");
		return;
	} 
	$.post("smbinfo.php",{act:"changebankpwd",oldpwd:oldpwd,newpwd:newpwd},function(ret){
		alert(ret.msg);
	},"json");
});
//发送消息
$("#btnSendTargetMsg").live('click',function(){ 
	var targetuser = $.trim($("#txtTargetUser").val());
	var targettitle = $.trim($("#txtTargetTitle").val());
	var targetmsg = $.trim($("#txtTargetMsg").val());
	
	if(targetuser == "" || isNaN(targetuser))
	{
		alert("请输入对方数字ID");
		return;
	}
	if(targettitle == "")
	{
		alert("请输入标题");
		return;
	}
	if(targetmsg == "")
	{
		alert("请输入内容");
		return;
	} 
	$.post("smbinfo.php",{act:"sendmsg",user:targetuser,title:targettitle,msg:targetmsg},function(ret){
		if(ret.cmd == 'ok')
		{
			alert(ret.msg);
			closerecord(0);
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});
//全选反选
function selectAll(n,t)
{
	if(t == 1)
	{
		$("input[name='"+ n +"']").each(function(){this.checked=true;});
	}
	else
	{
		$("input[name='"+ n +"']").each(function(){this.checked=!this.checked;});
	}
}
//取得勾选ID
function GetCheckID(n)
{
	var IDs = "";
	$("input[name='"+ n +"']:checked").each(function(){
		IDs += $(this).val() + ",";
	});
	if(IDs.length > 0)
	{
		IDs = IDs.substr(0,IDs.length-1);
	}
	return IDs;
}
//删除消息
function removeMsg(t)
{
	var IDs = GetCheckID('cbxUMID');
	if(IDs.length == 0)
	{
		alert("必须勾选一个!");
		return false;
	}
	if(confirm("您确定要删除所选消息吗?"))
	{
		$.post("smbinfo.php",{act:"removemsg",t:t,id:IDs},function(ret){
			alert(ret.msg);
		},"json");
		getContent("smbinfo.php?t=" + t, "messagelist");
	}
}
//发送手机验证码
$("#btnGetMobileValid").live('click',function(){ 
	var mobile = $("#txtBindMobile").val();
	var channel = $(":radio[name=uChannel]:checked").val()
	var reMobile = /^1\d{10}$/; 
	if(!reMobile.test(mobile))
	{
		alert("请填写您常用的手机号码");
		return;
	}
	$.post("smbinfo.php",{act:"sendmobilevalid",mobile:mobile,"channel":channel},function(ret){
		if(ret.cmd == 'ok')
		{
			$('#txtBindMobile').attr('disabled',true);
			alert("短信已发出，请检查手机");
			stopSec = 180;
			timerid = window.setInterval(function(){
				refreshTime("mobile");	
			},1000);
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});
//刷新函数
function refreshTime(vtype)
{
	var objAccount = "#txtBindMobile";
	var objBtn = "#btnGetMobileValid";
	var objLbl = "#lblBindtype";
	if(vtype == "email")
	{
		objAccount = "#txtBindEmail";
		objBtn = "#btnGetEmailValid";
	}
		
	if(stopSec < 0)
	{
		$(objBtn).val('重新发送');
		$(objBtn).attr('disabled',false);
		if($(objLbl).html() == "bind")
			$(objAccount).attr('disabled',false);
		clearInterval(timerid);
	}
	else
	{
		$(objBtn).attr('disabled',true);
		$(objBtn).val('还剩' + stopSec + '秒');
		stopSec--;
	}
}
//绑定QQ
$("#btnBindqq").live('click',function(){ 
	var qq = $("#txtBindqq").val();
	var validcode = $("#txtMobileValidCode").val();
	var reMobile =  /^[1-9]{1}\d{4,15}$/; 
	if(!reMobile.test(qq))
	{
		alert("请填写您常用的QQ");
		return;
	}
	if(validcode == "")
	{
		alert("请输入验证码");
		return;
	}
	$.post("smbinfo.php",{act:"bindqqact",qq:qq,code:validcode},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("绑定成功");
			closerecord(-1);
			getContent("smbinfo.php", "mydetail");
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});

//绑定手机
$("#btnBindMobile").live('click',function(){ 
	var mobile = $("#txtBindMobile").val();
	var validcode = $("#txtMobileValidCode").val();
	var reMobile = /^1\d{10}$/; 
	if(!reMobile.test(mobile))
	{
		alert("请填写您常用的手机号码");
		return;
	}
	if(validcode == "")
	{
		alert("请输入验证码");
		return;
	}
	$.post("smbinfo.php",{act:"bindmobile",mobile:mobile,code:validcode},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("绑定成功");
			closerecord(-1);
			getContent("smbinfo.php", "mydetail");
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});
//解绑手机
$("#btnUnBindMobile").live('click',function(){ 
	var validcode = $("#txtMobileValidCode").val();
	if(validcode == "")
	{
		alert("请输入验证码");
		return;
	}
	$.post("smbinfo.php",{act:"unbindmobile",code:validcode},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("解绑成功");
			closerecord(-1);
			getContent("smbinfo.php", "mydetail");
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});
//绑定邮箱
$("#btnToBindEmail").live('click',function(){ 
	var email = $("#txtEmail").val();
	re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(!re.test(email)){
    	alert("请输入常用的邮箱地址");
    	return;
    }
	$.post("smbinfo.php",{act:"bindemail",email:email},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("验证邮件已经发送到邮箱，请打开邮箱点击链接通过验证");
			closerecord(-2);
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});
//解绑邮箱
$("#btnToUnBindEmail").live('click',function(){ 
	var email = $("#txtEmail").val();
	re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(!re.test(email)){
    	alert("请输入常用的邮箱地址");
    	return;
    }
	$.post("smbinfo.php",{act:"unbindemail",email:email},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("验证已发到原邮箱，请打开邮箱点击链接完成解绑");
			closerecord(-2);
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
});


//领取奖励
function getrankings(id){ 
	$.post("smbinfo.php",{act:"GetRankings",id:id},function(ret){
		if(ret.cmd == 'ok')
		{
			alert("领取成功");
			getContent('smbinfo.php','rankings')		
		}
		else
		{
			alert(ret.msg);
		}
	},"json");
}

//取得工资
function recwage()
{
	$.post("smbinfo.php",{act:"recwage"},function(ret){	
		
		alert(ret.msg);
		if(ret.cmd == 'ok')
		{	
			getContent('smbinfo.php','wages')		
		}
	},"json");
}


//取得救济
function GetJiuji()
{
	$.post("smbinfo.php",{act:"getjiuji"},function(ret){
		alert(ret.msg);
	},"json");
}
//兑奖点卡
function ExchangeCard(cardtype)
{
	var amount = $("#txtcardtype_" + cardtype).val();
	if(amount == "" || isNaN(amount))
	{
		alert("请输入兑奖点卡数量");
		return;
	}
	if(confirm("您确定要兑奖吗?"))
	{
		$.post("smbinfo.php",{act:"exchangecard",cardtype:cardtype,amount:amount},function(ret){
			alert(ret.msg);
		},"json");
	}
}


function dl_txjl_act(vid)
{
	
	if(vid == "" || isNaN(vid))
	{
		alert("ID必须为数字!");
		return;
	}	
	$.post("smbinfo.php",{act:"dl_txjl_act",id:vid},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("操作成功!");
				getContent("smbinfo.php", "dl_txjl");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
}

//充值选择数额
$("#sltPayRMB").live('change',function(){ 
	var paypoint = $(this).children('option:selected').val();
	$("#txtPayPoint").val(paypoint*1000);
});
//去充值
$("#btnGoPay").live('click',function(){ 
	var payrmb = $("#sltPayRMB").val();
    if(payrmb == "" || isNaN(payrmb)){
    	alert("请正确选择充值金额");
    	return;
    }
	window.open('jbpay/jbtopay.php?rmb=' + payrmb);
});

//销售统计查询
$("#btndl_xstj").live('click',function(){ 
	dl_xstj();	
});

function dl_xstj(){
	
	var date1 = $.trim($("#date1").val());
	var date2 = $.trim($("#date2").val());
	
	if(date1 == "" || date2 == "")
	{
		alert("请选择日期!");
		return;
	}	
	
	$.post("smbinfo.php",{act:"dl_xstj",date1:date1,date2:date2},function(ret){
		$("#divContent").empty();		
		$("#divContent").html(ret);		
	});		
	
}


function dl_xstj_ks(d1,d2){		 
	$("#date1").val(d1);
	$("#date2").val(d2);
	dl_xstj();
}



$('#btnQueryCard').live("click", function(){

	var CardNo=$('#txtCardNo').val();
	
	$.ajax({type:'POST',url:'smbinfo.php',data:{act:"dl_cxdk_act",cardno:CardNo},dataType:"json",success:function(ret){
		
		if(ret.cmd == 'ok')
		{
			$('#cardprie').html(ret.c_price);
			$('#cardstate').html(ret.c_state);
			$('#cardtype').html(ret.c_type);
			$('#createuser').html(ret.c_fnickname);
			$('#createtime').html(ret.c_fctime);
			$('#useduser').html(ret.c_unickname);
			$('#usedtime').html(ret.c_uctime);	
		}
		else
		{
			alert(ret.msg);
		}
		
		
	}})

})


var kcfsj = 120;

function sendmess(param){
	kcfsj = 120;
	$('#sendcode').attr("disabled","true");
	channel = $(":radio[name=Channel]:checked").val();
	
	if(param==1){act='sendyzcode';}else{act='senddlyzcode';}
	
	
	$.ajax({type:'POST',dataType: "json",url:'smbinfo.php',async:true,data:{'act':act,'channel':channel,'t':(new Date()).getTime()},success:function(data){
	
		  if (data.status == 0) {
			  alert(data.msg);
			  statdjs();
		  } else {
			alert(data.msg);  
			$('#sendcode').removeAttr("disabled");
		  }

	}})
}

var djs;

function statdjs() {
    kcfsj = kcfsj - 1;
    if (kcfsj > 0) {
        $("#sendcode").html(kcfsj + "秒后可重新发送");
        djs=setTimeout("statdjs()", 1000);
    } else {
		$('#sendcode').removeAttr("disabled");
        $("#sendcode").html("重新发送");
    }
}

$(":radio[name=Channel]").live("change",function(){	
	if($(this).val()==4){
		url = $('#yzewm').attr("src");//"/wx/yzcode.php?_"+(new Date()).getMilliseconds();
		$('#yzewm').attr("src",url);
		$('#wxdiv').show();
		$('#sendcode').hide();
	}else{
		$('#wxdiv').hide();
		$('#sendcode').show();
	}	
})


$(":radio[name=uChannel]").live("change",function(){	
	if($(this).val()==4){
		url = $('#qqewm').attr("src");//"/wx/yzcode.php?_"+(new Date()).getMilliseconds();
		$('#qqewm').attr("src",url).show();
		$('#btnGetMobileValid').hide();
	}else{
		$('#qqewm').hide();
		$('#btnGetMobileValid').show();
	}	
})

function CheckAll(){		
	if($("#chkall").is(':checked')){
		$(":checkbox").attr("checked","checked");
	}else{
		 $(":checkbox").removeAttr("checked");
	}
}

function Checkscrad(){
	$(":checkbox").removeAttr("checked");		
	$('input[name="cradinput"]').attr("checked","checked");
}

function copykm(){
	copyvalues="";
	copyje=0;
	copynum=0;
	copymz=0;
	$(".ckkk:checked").each(function(i,e){
		copyvalues += $(e).attr("km")+"\r\n";
		copyje += parseFloat($(e).attr("je"));
		copymz += parseFloat($(e).attr("mz"));
		copynum += 1;
	})	
	if(copyvalues==""){
		copyvalues=" ";
	}
	copyvalues="卡密： "+copynum+" 张 ( 面值："+copyje+"豆 / "+ copymz+"元 ) \r\n"+copyvalues;
	return copyvalues;
}

function hbtypeshow(){
	$('#hbje').val('');
	$('#hbzje').val('');
	$('#hbjeshow').html('0')
	$('#hbjeshow2').html('0')
	$('.hbshow').toggle();
	
}

function hbjeshow(){
	hbje=$('#hbje').val()
	hbzje=$('#hbzje').val()
	hbnum=$('#hbnum').val()
	if($('#hbtype').val()=='1'){		
		if(isNaN(hbje) || hbje==""){hbje=0;}
		if(isNaN(hbnum) || hbnum==""){hbnum=0;}
		$('#hbjeshow').html(parseInt(hbje)*parseInt(hbnum));
		$('#hbjeshow2').html(parseInt(parseInt(parseInt(hbje)*parseInt(hbnum)*(v_discount*1000))/1000));								
	}else{
		if(isNaN(hbzje) || hbzje==""){hbzje=0;}	
		$('#hbjeshow').html(parseInt(hbzje));
		$('#hbjeshow2').html(parseInt(parseInt(parseInt(hbzje)*(v_discount*1000))/1000));					
	}
}

var smv='恭喜发财，大吉大利！';
function hbsmb(){
	if($('#hbsm').val()==''){
		$('#hbsm').val(smv);
	}
}

function hbsmf(){
	if($('#hbsm').val()==smv){
		$('#hbsm').val('');
	}
}

function free_hb(){
	$.post("smbinfo.php",{act:"freehb"},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("红包生成成功!");
				getContent("smbinfo.php", "hongbaolist");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
		
}

//生成红包
$("#bthbadd").live('click',function(){ 
	var hbnum = $("#hbnum").val();
	var hbje = $("#hbje").val();
	var hbzje = $("#hbzje").val();
	var hbtype = $("#hbtype").val();
	var hbsm = $("#hbsm").val();
	if(hbnum == "" || isNaN(hbnum))
	{
		alert("红包总个数必须为正整数!");
		return;
	}
	if(hbtype != "1" && hbtype != "2")
	{
		alert("红包类型错误!");
		return;
	}
	
	if(hbtype=="1"){
		
		if(hbje == "" || isNaN(hbje))
		{
			alert("单个红包金额必须为数字!");
			return;
		}		
	}else{
		if(hbzje == "" || isNaN(hbzje)){		
			alert("红包总金额必须为数字!");
			return;
		}
	}

	if(hbsm == "" || hbsm.length > 20){		
		alert("红包说明不能为空或超过20个字!");
		return;
	}
	
	hbnum = parseInt(hbnum);
	hbje = parseInt(hbje);
	hbzje = parseInt(hbzje);
	hbtype = parseInt(hbtype);
	$.post("smbinfo.php",{act:"hongbaoact",hbnum:hbnum,hbtype:hbtype,hbje:hbje,hbzje:hbzje,hbsm:hbsm},function(ret){
		switch(ret.cmd)
		{
			case "ok":
				alert("红包生成成功!");
				getContent("smbinfo.php", "hongbaolist");
				break;
			default:
				alert(ret.msg);
				break;
		}	
	},"json");
})


